package com.zrrd.yt.product.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrrd.yt.common.result.Result;
import com.zrrd.yt.model.product.BaseTrademark;
import com.zrrd.yt.product.service.TrademarkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author HongyueYang
 */
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class TrademarkController {

    @Autowired
    private TrademarkService trademarkService;

    //查询全部品牌列表
    @GetMapping("/getTrademarkList")
    public Result<List<BaseTrademark>> getTrademarkList() {
        return Result.ok(trademarkService.list(null));

    }

    //分页查询品牌列表
    @GetMapping("/{page}/{limit}")
    public Result<Page> page(@PathVariable("page") Integer page,
                             @PathVariable("limit") Integer limit) {

        Page<BaseTrademark> pageInfo = new Page<>(page, limit);
        trademarkService.page(pageInfo, null);
        return Result.ok(pageInfo);
    }

    //添加品牌
    @PostMapping("/save")
    public Result<String> save(@RequestBody BaseTrademark baseTrademark) {
        return trademarkService.save(baseTrademark)? Result.ok("成功") : Result.fail("失败");
    }

    //修改品牌
    @PutMapping("/update")
    public Result<String> update(@RequestBody BaseTrademark baseTrademark) {
        trademarkService.updateById(baseTrademark);
        return trademarkService.updateById(baseTrademark)? Result.ok("成功") : Result.fail("失败");
    }

    //删除品牌
    @DeleteMapping("/remove/{id}")
    public Result<String> remove(@PathVariable("id") Long id){
        return trademarkService.removeById(id)? Result.ok("成功") : Result.fail("失败");
    }












}
